'''
 * CaRComp Execution Environment
 * 
 * Copyright (C) 2011 Taylor L. Riche
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
'''

import unittest
from carcomp.apps.gamma.util import bitmap


class Test(unittest.TestCase):


    def test_serialize(self):
        bm = bitmap.BitMap(8)
        bm.set(0)
        bm.set(7)
        self.assertEqual(bm.serialize(), '10000001')
        
    def test_bad_index(self):
        bm = bitmap.BitMap(8)
        self.assertRaises(IndexError, bm.set, 8)
        
    def test_set_string(self):
        bm = bitmap.BitMap(8, '01010101')
        self.assertEqual(bm.serialize(), '01010101')
        
    def test_set_string_size_mismatch(self):
        self.assertRaises(bitmap.SizeMismatchError, bitmap.BitMap, 5, '010101')
        
    def test_set_string_bad_val(self):
        self.assertRaises(bitmap.BadStringValError, bitmap.BitMap, 8, 'blahblah')

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.test_serialize']
    unittest.main()